<html>
<head><meta charset="utf-8"><title>nondeterminism in tests? · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html">nondeterminism in tests?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="166746030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166746030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166746030">(May 28 2019 at 18:36)</a>:</h4>
<div class="codehilite"><pre><span></span>thread &#39;hover::tests::hover_shows_fn_signature&#39; panicked at &#39;assertion failed: `(left == right)`
  left: `&quot;pub fn foo() -&gt; u32&quot;`,
 right: `&quot;pub fn foo() -&gt; &amp;str&quot;`&#39;, crates/ra_ide_api/src/hover.rs:162:13
</pre></div>



<a name="166788197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166788197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166788197">(May 29 2019 at 06:39)</a>:</h4>
<p>huh, that seems bad!</p>



<a name="166788421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166788421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166788421">(May 29 2019 at 06:44)</a>:</h4>
<p><span class="user-mention" data-user-id="203546">@Laurențiu Nicola</span> I can't reproduce it locally. Which version of Rust are you using (I <em>think</em> nightly's hash-brown could have changed things)</p>



<a name="166788538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166788538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166788538">(May 29 2019 at 06:47)</a>:</h4>
<p>a nightly</p>



<a name="166788540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166788540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166788540">(May 29 2019 at 06:47)</a>:</h4>
<p>rustc 1.36.0-nightly (7158ed9cb 2019-05-15)</p>



<a name="166788868"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166788868" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166788868">(May 29 2019 at 06:54)</a>:</h4>
<p>Aha, will try to look into that!</p>



<a name="166788895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166788895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166788895">(May 29 2019 at 06:55)</a>:</h4>
<p>no worries, I tried to check whether they're sorted, but didn't see anything</p>



<a name="166788968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166788968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166788968">(May 29 2019 at 06:57)</a>:</h4>
<p>ah, yeah, this is much better than I've expected, we don't have a non-deterministic type inference, it's just the test itself that relies on the order of iteration</p>



<a name="166789020"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166789020" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166789020">(May 29 2019 at 06:58)</a>:</h4>
<p>In the <code>let hover = analysis.hover(position).unwrap().unwrap();</code></p>



<a name="166789034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166789034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166789034">(May 29 2019 at 06:58)</a>:</h4>
<p>We basically should add <code>hover.sort()</code>, adjust the tests, and make sure all <code>#[derive(Ord)]</code> are present to actually be able to sort hovers</p>



<a name="166789066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166789066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166789066">(May 29 2019 at 06:59)</a>:</h4>
<p>I wonder how many projects will be broken in practice due to different order of iteration.... ? :D</p>
<p>I've already fixed a couple of similar bugs when I was trying the nightly out</p>



<a name="166789319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166789319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166789319">(May 29 2019 at 07:04)</a>:</h4>
<p>Sure, but in the long run do we want to prioritize or sort hover references before showing them?</p>



<a name="166789425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166789425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166789425">(May 29 2019 at 07:06)</a>:</h4>
<p>And wasn't there a random seed used by hashmaps that should change the iteration order from one run to another?</p>



<a name="166789511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166789511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166789511">(May 29 2019 at 07:08)</a>:</h4>
<p>Maybe? I don't know an obvious rule to sort hovers though, and I don't think that's really important, so sorting in tests seems fine</p>



<a name="166789529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166789529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166789529">(May 29 2019 at 07:08)</a>:</h4>
<blockquote>
<p>And wasn't there a random seed used by hashmaps that should change the iteration order from one run to another?</p>
</blockquote>
<p>Good observation! I think, because we are using <code>FxHashMap</code>, we don't do randomization</p>



<a name="166789550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166789550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166789550">(May 29 2019 at 07:09)</a>:</h4>
<p>we probably should though...</p>



<a name="166789559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166789559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166789559">(May 29 2019 at 07:09)</a>:</h4>
<p>at least for tests</p>



<a name="166789580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166789580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166789580">(May 29 2019 at 07:10)</a>:</h4>
<p>Sorting only in the test should work for now, though</p>



<a name="166789638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism%20in%20tests%3F/near/166789638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/nondeterminism.20in.20tests.3F.html#166789638">(May 29 2019 at 07:10)</a>:</h4>
<p>agree!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>